<?php
Yii::import('application.components.dao.class.Dao');
class RegisterDao extends Dao{
   	
    public function attributeLabels(){
        return array(
            'title' => 'Auction Title',
            'winner_price' => 'Initial Auction Price',
            'winner_price_increment' => 'Bidding Increment'
        );
    }
        
    public function register(){
    	return $this->save();
    }
    
    public function dataSource(){
        return array(
        	'Customer' => array(
        		'attributes'    => array(
        			'id','user_name','password','created','status','email','verifyCode','is_agree','conemail','conpassword','verifyCode','salt'
        		),
        	),
        	'CustomerInfo' => array(
        		'attributes'    => array(
                    'customer_id',
					'first_name',
					'last_name',
					'address',
					'city',
					'zip_code',
					'states',
					'phone',
					'BIO',
					'birthday',
					'avatar',
        		    'ip',
        		    'refer',
        		),
        	)
        );
    }
    public function rules(){
    	return array(
    	    array('birthday','birExist'),
    	);
    }
    public function birExist($attribute,$params){
        $now=time();
        $check_18=strtotime('-18 year ');
        $birthday=strtotime($this->birthday);
        if(($now-$birthday)<=($now-$check_18)){
            $this->addError($attribute,'You are less than 18 years old');
        }else {
            $this->clearErrors($attribute);
        }
    }
    public function dataSourceRelations(){
    	return array(
    		'Customer' => array(
    			'CustomerInfo'	=> array('part','join' => array('id' => 'customer_id'))
    		)
    	);
    }
}